﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace LearningBubbles
{
    static class Gui
    {
        private static Vector2 guiPosition = new Vector2(Textures.KinectRGBVideo.Width, 0);

        private static ProgressBar progressBar;
        private static Textbox textbox;

        public static Vector2 GuiPosition
        {
            get { return Gui.guiPosition; }
            set { Gui.guiPosition = value; }
        }

        public static ProgressBar ProgressBar
        {
            get { return progressBar; }
            set { progressBar = value; }
        }

        public static Textbox Textbox
        {
            get { return textbox; }
            set { textbox = value; }
        }

        //Load all elements of the gui
        //Also loads world so that the assignment
        //and all its desired parameters can be loaded
        //and viewed within the Gui
        public static void LoadGui(GraphicsDeviceManager g, Vector2 position, World world, Game1 game, BubbleObservable bo)
        {
            int w = (int)GetGuiBounds(g).X;
            int h = (int)GetGuiBounds(g).Y;
            Textures.GuiBackGround = DrawGuiBackGround(g.GraphicsDevice, w, h, Color.LightGray);
            DrawProgressBar(g.GraphicsDevice, (int) GuiPosition.X + 65, (int) GuiPosition.Y + 450, world, game);
            textbox = new Textbox(game, new Rectangle((int)GuiPosition.X, (int)GuiPosition.Y,
                Textures.GuiBackGround.Width, Textures.GuiBackGround.Height-50), world.Assignment.Text, bo);
        }

        //Get the bounds of the GUI
        public static Vector2 GetGuiBounds(GraphicsDeviceManager g) {
            return new Vector2(g.PreferredBackBufferWidth - Textures.KinectRGBVideo.Width, g.PreferredBackBufferHeight);
        }

        //http://stackoverflow.com/questions/2792694/draw-rectangle-with-xna
        //Draw a rectangle illustrating the GUI background 
        public static Texture2D DrawGuiBackGround(GraphicsDevice g, int width, int height, Color colori)
        {
            Texture2D rectangleTexture = new Texture2D(g, width, height, false, SurfaceFormat.Color);
            Color[] color = new Color[width * height];
            for (int i = 0; i < color.Length; i++)
            {
                color[i] = colori;
            }
            rectangleTexture.SetData(color);
            return rectangleTexture;
        }

        public static void DrawProgressBar(GraphicsDevice g, int width, int height, World world, Game1 game)
        {
            ProgressBar = new ProgressBar(game,
                     new Rectangle(width,
                    height , 200, 16));
            ProgressBar.minimum = 0;
            ProgressBar.maximum = world.Assignment.Elements.Count;
        }


    }
}
